package cn.itcast.service.user;

import cn.itcast.model.SysUser;
import cn.itcast.repository.SysUserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

/**
 * @Author: zhaojie
 * @Date: Created in 16:20 2018/8/9
 * @Description: 验证用户信息
 */
public class CustomUserService implements UserDetailsService {

    @Autowired
    private SysUserRepository sysUserMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        SysUser byUsername = sysUserMapper.findByUsername(username);
        if (byUsername == null) {
            System.out.println("用户名密码错误");
            throw new UsernameNotFoundException("用户名不存在");
        }

        return byUsername;
    }
}
